//
//  CQNewFeatureCell.m
//  01-OC微博
//
//  Created by 陈乾 on 15/10/27.
//  Copyright © 2015年 陈乾. All rights reserved.
//

#import "CQNewFeatureCell.h"
#import "CQTabBarController.h"

@interface CQNewFeatureCell()

@property (nonatomic, weak) UIImageView *imageView;

@property (nonatomic, strong) UIButton *beginBtn;

@end

@implementation CQNewFeatureCell
//懒加载
-(UIImageView *)imageView{
    if (_imageView == nil) {
        UIImageView *imageV = [[UIImageView alloc] init];
        _imageView = imageV;
#warning 注意：tabbleview和collectionView的cell添加子控件最好添加到contentView上面
        [self.contentView addSubview:imageV];
        
        
        
    }
    return _imageView;
}

//懒加载一个按钮
-(UIButton *)beginBtn {
    if (_beginBtn == nil) {
        _beginBtn = [[UIButton alloc] init];
        //背景图片
        [_beginBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
        [_beginBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
        //默认隐藏
        _beginBtn.hidden = YES;
        //设置大小
        [_beginBtn sizeToFit];
        //标题
        [_beginBtn setTitle:@"开始体验" forState:UIControlStateNormal];
        //监听事件点击
        [_beginBtn addTarget:self action:@selector(jump2Tab) forControlEvents:UIControlEventTouchUpInside];
#warning 注意 这里不能添加到contenview上 否者 frame失效
        [self addSubview:_beginBtn];
    }
    return  _beginBtn;
}


#pragma mark - 控制第几个cell才显示按钮
-(void)showBeginBtnIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 3) {
        self.beginBtn.hidden = NO;
    }
}


#pragma mark - 点击开始体验
- (void)jump2Tab {
  
    //拿到根控制器跳转
    CQTabBarController *tabVc = [[CQTabBarController alloc] init];
    //怼给 rootViewController
    CQKeyWindow.rootViewController = tabVc;
    
    
    
    
}


//布局
-(void)layoutSubviews
{
    [super layoutSubviews];
    //水平居中
    _beginBtn.center = CGPointMake([UIScreen mainScreen].bounds.size.width *0.5,[UIScreen mainScreen].bounds.size.height *0.9);
    
    //占据整个cell
    self.imageView.frame = self.bounds;
}
//设置image的值
-(void)setImage:(UIImage *)image
{
    _image = image;
    
    self.imageView.image = image;
    
    
}

@end
